import {add_user_info,logout} from "../../constant/baseConstant";

const name = localStorage.getItem('username')
const token = localStorage.getItem('token');
const init = {
    username:name,
    token:token,
    isLogin: !!(name && token)
}
export default function userReducer(preState = init,action) {
    const {type,data} = action
    switch (type) {
        case add_user_info:
            return {
                username:data.username,
                token:data.token,
                isLogin: true
            }
        case logout:
            return {
                username: '',
                token: '',
                isLogin: false
            }
        default:
            return preState
    }
}